<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3" xmlns:head="http://www.w3.org/1999/html">
<head th:include="public/public_css::public_css ('产品预警分析')" />

<body style="background-color: #f2f2f2;">
<div class="layui-fluid larry-wrapper">
    <div class="layui-card">
        <div class="layui-row layui-col-space30">
            <div class="layui-col-xs24">
                <form class="layui-form layui-card-header  layui-card-header-auto" id="searchForm">
                    <div class="layui-inline" style="width: 190px">
                        <label class="layui-form-label">产品编码</label>
                        <div class="layui-inline">
                            <input type="text" name="cpbm" placeholder="请输入产品编码"  class="layui-input" style="width: 190px">
                        </div>
                    </div>
                    <div class="layui-inline" style="width: 190px">
                        <label class="layui-form-label">产品名称</label>
                        <div class="layui-inline">
                            <input type="text" name="cpmc" placeholder="请输入产品名称"  class="layui-input" style="width: 190px">
                        </div>
                    </div>
                    <div class="layui-inline" style="width: 190px">
                    <label class="layui-form-label">产品类型</label>
                    <div class="layui-inline">
                        <input type="text" name="cplx" placeholder="请输入产品类型"  class="layui-input" style="width: 190px">
                    </div>
                </div>
                    <div class="layui-inline inline-search-btn">
                        <a class="layui-btn layui-btn-normal" data-type="reload" id="search_button"> 搜索 </a>
                    </div>
                    <div class="layui-inline inline-reset-btn">
                        <button type="reset" class="layui-btn layui-btn-primary" onclick="queryTable()" style="background-color: #40AFFE">重置</button>
                    </div>
                    <!--<input type="hidden" id="fpsj_start" name="fpsj_start">-->
                    <!--<input type="hidden" id="fpsj_end" name="fpsj_end">-->

                </form>
                <div class="moreBtn"><i class="layui-icon layui-icon-triangle-d" style="color: #1E9FFF;"></i></div>
                <div class="group-button" id="toolbar">
                    <a class="layui-btn layui-btn-sm layui-btn-normal  out-put" >
                        <i class="layui-icon">&#x1005;</i> 导出
                    </a>
                </div>
                <!--列表-->
                <section class="panel panel-padding layui-card-body" >
                    <div class="pro">
                        <table id="table"></table>
                    </div>
                </section>
            </div>
        </div>
    </div>
</div>
</body>

<div th:include="public/public_js::public_js"></div>
<script>
    //	回车查询
    document.onkeydown = function(event) {
        e = event ? event : (window.event ? window.event : null);
        if (e.keyCode == 13) {
            //执行的方法
            $('#search_button').click();
        }
    };
    $(function () {
        $(".moreBtn").on("click",function () {
            $(".moreSearch").toggle();
        })
    })
    layui.use(['list','layer','zzpUtils','jquery','laydate'],function () {
        var zzpUtils= layui.zzpUtils,
            $ = layui.jquery,
            laydate = layui.laydate;
        //创建时间开始
//        laydate.render({
//            elem: '#fpsj',
//            type: 'date',
//            range:'~',
//            done: function(value, date, endDate){
//                if(value!=null && value !=""){
//                    var fpsj_start=value.toString().substring(0,value.toString().indexOf("~"));
//                    var fpsj_end=value.toString().substring(value.toString().indexOf("~")+1);
//                    $("#fpsj_start").val(Date.parse(new Date(fpsj_start)));
//                    $("#fpsj_end").val(Date.parse(new Date(fpsj_end)));
//                }else {
//                    $("#fpsj_start").val("");
//                    $("#fpsj_end").val("");
//                }
//
//
//                /*  alert(Date.parse(new Date($("#fpsj_start").val())));
//                 alert("2018-8-1:"+Date.parse(new Date("2018-8-1")));
//                 alert("2018-08-01:"+Date.parse(new Date("2018-08-01")));
//
//                 console.log(value); //得到日期生成的值，如：2017-08-18
//                 console.log(date); //得到日期时间对象：{year: 2017, month: 8, date: 18, hours: 0, minutes: 0, seconds: 0}
//                 console.log(endDate); //得结束的日期时间对象，开启范围选择（range: true）才会返回。对象成员同上。*/
//            }
//        });
        laydate.render({
            elem: '#test5'
            ,theme: '#20a0ff'
        })
        //select2 查货品种类
        $('.js-data-example-ajax').select2({
            ajax: {
                url: '/zxsswms/wmsgoodstype/getWmsGoodsTypeByHzId',
                dataType: 'json',
                type: 'POST',
                contentType: "application/json",
                data: function (params) {
                    var query = {
                        mc: params.term
                    };
                    return JSON.stringify(query);
                },
                processResults: function (data) {
                    var arr= new Array();
                    if(data){
                        for (var i=0;i<data.length;i++){
                            arr.push({id:data[i].mc,text:data[i].mc});
                        }
                    }
                    console.log(arr);
                    return {
                        results: arr
                    };
                },
                cache: true
            },
            language: "zh-CN",
            placeholder: '请输入查询货品种类',
            allowClear: true
        });
        window.operateEvent ={
            "click .layui-btn-primary":function (e, value, row, index) {
                alert(row.mc);
            }
        }
        //查询list
        var $table = zzpUtils.table({
            elem: '#table',
            isApi: true,
            pagination:true,
            striped: true,
            url: '/wmsproductWarning/baseHarvestPage',
            columns: [{
                field: '',
                checkbox: true
            },{
                field: 'cplx',
                title: '产品类型'
            },{
                field: 'cpbm',
                title: '产品编码'
            }, {
                field: 'cpmc',
                title: '产品名称'
            },{
                field: 'jskc',
                title: '总库存'
            },{
                field: 'ljqsl',
                title: '临近期库存'
            },{
                field: 'sxsl',
                title: '过期库存'
            },{
                field: 'jsyxl',
                title: '近三月数量'
            },{
                field: 'kcbhyj',
                title: '库存补货预警',
            },{
                field: 'zckc',
                title: '正常库存',
            },{
                field: 'gysmc',
                title: '供应商名称',
                visible: false
            },{
                field: 'hppc',
                title: '货品批次',
                visible: false
            },{
                field: 'fpsj',
                title: '分配时间',
                visible: false
            },
            ],
            queryParams: function () {//查询条件
                return  zzpUtils.getFormJson($("#searchForm"));
            },
            detailFormatter: function (index, row) {
                return "这里就没有确定过11";
            }
        });

        $(".inline-search-btn").on('click',function () {
            zzpUtils.refreshTable("#table");
        });

        /*顶部按钮导出 */
        $(".out-put").on('click', function () {
            console.log('导出');
            var arr=[];
            var $rows = $table.bootstrapTable('getSelections');
            if ($rows.length >0) {
                arr = $.map($rows, function (row) {
                    return row.cpid;
                })
            }
            /*
             * 以下是将ids和对象拼接在一起
             * */
            var obj = [];
            for(var i=0;i<arr.length;i++) {
                var person = {};
                person[i] = arr[i];
                obj.push(person);
            }
            var str=zzpUtils.getFormJson($("#searchForm"));
            var object2 = Object.assign({ids: arr}, str);
            /*将条件查询和ids传到后台*/
//            str.send();
            zzpUtils.outputXslx({
                url:"/wmsproductWarning/exportWmsproductWarning",
                data:JSON.stringify(object2)
            });
        })//导出结束


        /*顶部按钮多选启用*/
        $("#btn_qi").on('click', function () {
            var index = 0;
            var $rows = $table.bootstrapTable('getSelections');

        })
        window.queryTable = function () {
//            alert('重置');
            var formdata = $("form").serializeArray();
            var DATA = {};
            console.log('formdata',formdata);
//           var  cjsj_start = '', cjsj_end = '';
//            DATA.cjsj_start = "";
//            DATA.cjsj_end = "";
            DATA.cpbm = "";
            DATA.cplx = "";
            DATA.cpmc = "";
            DATA.page = 1;
            DATA.rows = 10;
            $('#table').bootstrapTable('refresh',{
                query: DATA
            })
        }
    });
</script>
</html>